<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品名" prop="comName">
        <el-input
          v-model="queryParams.comName"
          placeholder="请输入商品名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账号" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="auditShopList">
      <el-table-column label="商品名" align="center" prop="comName" />
      <el-table-column label="商品类别" align="center" prop="typeName" />
      <el-table-column label="原价" align="center" prop="oriMoney" />
      <el-table-column label="售价" align="center" prop="soldMoney" />
      <el-table-column
        label="发布时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column
        label="结束时间"
        align="center"
        prop="endTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="状态" align="center" prop="comStatus">
        <template slot-scope="scope">
          <dict-tag :options="comStatusOptions" :value="scope.row.comStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAudit(scope.row)"
            v-hasPermi="['campus:audit:shop']"
          >审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body  class="my-info-dialog">
      <div style="padding: 0 10px;">
        <el-row style="padding: 12px;font-size: 15px;">
          <el-col>
            <span style="font-weight: bold">商品名：</span>
            <span>{{detailData.comName}}</span>
          </el-col>
        </el-row>
        <el-row style="padding: 12px;font-size: 15px;">
          <el-col :span="12">
            <span style="font-weight: bold">原价：</span>
            <span>{{detailData.oriMoney}}</span>
          </el-col>
          <el-col :span="12">
            <span style="font-weight: bold">售价：</span>
            <span>{{detailData.soldMoney}}</span>
          </el-col>
        </el-row>
        <el-row style="padding: 12px;font-size: 15px;">
          <el-col :span="12">
            <span style="font-weight: bold">图片：</span>
          </el-col>
        </el-row>
        <el-row style="padding: 12px;font-size: 15px;">
          <imageUpload v-model="detailData.imgUrl" />
        </el-row>
        <el-row style="padding: 12px;font-size: 15px;">
          <el-col :span="12">
            <span style="font-weight: bold">商品描述：</span>
          </el-col>
        </el-row>
        <el-row style="padding: 12px;font-size: 15px;">
          <el-col>
            <span v-html="detailData.comDesc"></span>
          </el-col>
        </el-row>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="passAudit">通 过</el-button>
        <el-button type="danger" @click="outAudit">违 规</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listShop, getAuditShop, passAuditShop, outAuditShop } from '@/api/campus/audit'

  export default {
    name: 'auditShop',
    data() {
      return {
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 审核的商品的相关信息表格数据
        auditShopList: [],
        // 状态 0违规 1正常 2已删除 3待审核 4已售出字典
        comStatusOptions: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          comName: null,
          userName: null
        },
        // 详细数据
        detailData: {}
      }
    },
    created() {
      this.getList()
      this.getDicts("commodity_status").then((response) => {
        this.comStatusOptions = response.data;
      });
    },
    methods: {
      /** 查询所有要审核的商品的相关信息 */
      getList() {
        this.loading = true
        listShop(this.queryParams).then(response => {
          this.auditShopList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 数据重置
      reset() {
        this.detailData = {}
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      /** 审核按钮操作 */
      handleAudit(row) {
        this.reset()
        const comId = row.comId
        getAuditShop(comId).then(response => {
          this.detailData = response.data
          this.open = true
          this.title = '审核商品信息'
        })
      },
      /** 审核通过按钮 */
      passAudit() {
        var self = this;
        self.$confirm('是否通过商品名为"' + this.detailData.comName + '"的审核', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return passAuditShop(self.detailData.comId)
        }).then(() => {
          self.getList();
          self.open = false;
          self.msgSuccess("审核成功")
        }).catch(() => {});
      },
      /** 审核违规按钮 */
      outAudit() {
        var self = this;
        self.$confirm('是否确定该商品违规', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return outAuditShop(self.detailData.comId)
        }).then(() => {
          self.getList();
          self.open = false;
          self.msgSuccess("审核成功")
        }).catch(() => {});
      }
    }
  }
</script>
<style>
  .my-info-dialog .el-upload--picture-card{
    display: none;
  }
  .my-info-dialog .el-icon-delete{
    display: none;
  }
  .my-info-dialog .el-upload__tip{
    display: none;
  }
  .my-info-dialog .el-icon-zoom-in{
    padding-left: 15px;
  }
</style>
